package cn.fboost.mtos.task;

import cn.fboost.mtos.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class OrderTask {
    private final OrderMapper orderMapper;

    public OrderTask(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    /**
     * 自动确认收货订单，5分钟执行一次
     */
    @Scheduled(fixedRate = 1000 * 60 * 5)
    public void autoFinish() {
        int total = orderMapper.autoFinish();
        log.info("自动确认收货订单，共确认{}条", total);
    }

    /**
     * 自动关闭未支付订单，5分钟执行一次
     */
    @Scheduled(fixedRate = 1000 * 60 * 5)
    public void autoClose() {
        int total = orderMapper.closeUnpaidOrder();
        log.info("自动关闭未支付订单，共关闭{}条", total);
    }
}
